package menu;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

import state.GameState;
import chesskers.Driver;
import chesskers.ImagePanel;
import chesskers.UIManager;
import chesskers.Driver.GameStateEnum;

public class MainMenuFrame extends MenuWindow{
	
	ImagePanel panel_mainmenu = new ImagePanel(new ImageIcon("img/mm_background.png").getImage());
	JButton button_mm_newchess = new JButton("Play New Chess Match");
	JButton button_mm_newcheck = new JButton("Play New Checkers Match");
	JButton button_mm_loadchess = new JButton("Load Chess Match");
	JButton button_mm_loadcheck = new JButton("Load Checkers Match");
	JButton button_mm_historychess = new JButton("View Chess Match History");
	JButton button_mm_historycheck = new JButton("View Checkers Match History");
	JButton button_mm_quit = new JButton("Quit");
	
	public MainMenuFrame() {
		super("Chess-kers!");
		
		button_mm_newchess.setBounds(25, 50, 200, 50);
		MakeButtonAction(button_mm_newchess, "newchess");
		button_mm_loadchess.setBounds(25, 125, 160, 50);
		MakeButtonAction(button_mm_loadchess, "loadchess");
		button_mm_newcheck.setBounds(360, 50, 200, 50);
		MakeButtonAction(button_mm_newcheck, "newcheck");
		button_mm_loadcheck.setBounds(400, 125, 160, 50);
		MakeButtonAction(button_mm_loadcheck, "loadcheck");
		button_mm_historychess.setBounds(25, 360, 250, 50);
		MakeButtonAction(button_mm_historychess, "historychess");		
		button_mm_historycheck.setBounds(310, 360, 250, 50);
		MakeButtonAction(button_mm_historycheck, "historycheck");
		button_mm_quit.setBounds(140, 415, 300, 30);
		MakeButtonAction(button_mm_quit, "quit");		
		
		panel_mainmenu.add(button_mm_newchess);
		panel_mainmenu.add(button_mm_loadchess);
		panel_mainmenu.add(button_mm_newcheck);
		panel_mainmenu.add(button_mm_loadcheck);
		panel_mainmenu.add(button_mm_historychess);
		panel_mainmenu.add(button_mm_historycheck);
		panel_mainmenu.add(button_mm_quit);
		
		this.add(panel_mainmenu);
		
		setSize(600, 500);
		setBackground(Color.red);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setResizable(false);
        setVisible(true);
	}

	@Override
	public void Action(String cmd) {
		switch (cmd) {
		case "historycheck":
			Driver.state = Driver.state.HistoryCheck;
			new UIManager().start();
		    dispose();
			break;
		case "historychess":
			Driver.state = Driver.state.HistoryChess;
			new UIManager().start();
		    dispose();
			break;	
		case "loadchess":
			Driver.state = Driver.state.LoadChess;
			new UIManager().start();
		    dispose();
			break;	
		case "loadcheck":
			Driver.state = Driver.state.LoadCheck;
			new UIManager().start();
		    dispose();
			break;	
		case "newcheck":
			Driver.state = Driver.state.CheckSelect1;
			new UIManager().start();
		    dispose();
			break;		
		case "newchess":
			Driver.state = Driver.state.ChessSelect1;
			new UIManager().start();
		    dispose();
			break;				
		case "quit":
			System.exit(0);
			break;		
		default:
			throw new UnsupportedOperationException("Invalid button code: "+cmd);
		}
	}
	

}